package com.example.xianji.activity;

import android.os.Bundle;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.RelativeLayout;

import com.example.xianji.Contant;
import com.example.xianji.R;
import com.example.xianji.constant.Constant;
import com.example.xianji.utils.sp.PreferenceEngine;

/**
 * 产品管理页面
 *
 * @author me
 */
public class Main_Product_GuanLiActivity extends Activity implements OnClickListener {
    private RelativeLayout relativelayout_send_product, relativelayout_my_send_product, relativelayout_add_fenlei, relativelayout_product_fenlei, relativelayout_my_send_buy_product, relativelayout_my_receive_liuyan, relativelayout_my_collection_product, relativelayout_send_product_buy,
            relativelayout_my_liuyan, product_relative_guanli_back;
//    private SharedPreferences sp;
//    private Editor ed;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
        setContentView(R.layout.activity_main__product__guan_li);
//        sp = getSharedPreferences("text", MODE_PRIVATE);
//        ed = sp.edit();

        relativelayout_send_product = (RelativeLayout) findViewById(R.id.relativelayout_send_product);
        relativelayout_my_send_product = (RelativeLayout) findViewById(R.id.relativelayout_my_send_product);
        relativelayout_add_fenlei = (RelativeLayout) findViewById(R.id.relativelayout_add_fenlei);
        relativelayout_product_fenlei = (RelativeLayout) findViewById(R.id.relativelayout_product_fenlei);
        relativelayout_my_send_buy_product = (RelativeLayout) findViewById(R.id.relativelayout_my_send_buy_product);
        relativelayout_my_receive_liuyan = (RelativeLayout) findViewById(R.id.relativelayout_my_receive_liuyan);
        relativelayout_my_collection_product = (RelativeLayout) findViewById(R.id.relativelayout_my_collection_product);
        relativelayout_my_liuyan = (RelativeLayout) findViewById(R.id.relativelayout_my_liuyan);
        product_relative_guanli_back = (RelativeLayout) findViewById(R.id.product_relative_guanli_back);
        relativelayout_send_product_buy = (RelativeLayout) findViewById(R.id.relativelayout_send_product_buy);


        relativelayout_send_product.setOnClickListener(this);
        relativelayout_my_send_product.setOnClickListener(this);
        relativelayout_add_fenlei.setOnClickListener(this);
        relativelayout_product_fenlei.setOnClickListener(this);
        relativelayout_my_send_buy_product.setOnClickListener(this);
        relativelayout_my_receive_liuyan.setOnClickListener(this);
        relativelayout_my_collection_product.setOnClickListener(this);
        relativelayout_my_liuyan.setOnClickListener(this);
        product_relative_guanli_back.setOnClickListener(this);
        relativelayout_send_product_buy.setOnClickListener(this);
        //个人用户
        if (PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("FP") ||
                PreferenceEngine.getInstance().getString(Constant.SP.NAME, Constant.SP.KEY_XIANJI_TYPE, "").equals("AP")) {

            relativelayout_send_product.setVisibility(View.GONE);
            relativelayout_my_send_product.setVisibility(View.GONE);
            relativelayout_add_fenlei.setVisibility(View.GONE);
            relativelayout_product_fenlei.setVisibility(View.GONE);
            relativelayout_my_send_buy_product.setVisibility(View.GONE);
            relativelayout_my_receive_liuyan.setVisibility(View.GONE);
            relativelayout_send_product_buy.setVisibility(View.GONE);

        } else {
            //企业用户
            relativelayout_send_product.setVisibility(View.VISIBLE);
            relativelayout_my_send_product.setVisibility(View.VISIBLE);
            relativelayout_add_fenlei.setVisibility(View.VISIBLE);
            relativelayout_product_fenlei.setVisibility(View.VISIBLE);
            relativelayout_my_send_buy_product.setVisibility(View.VISIBLE);
            relativelayout_my_receive_liuyan.setVisibility(View.VISIBLE);
            relativelayout_send_product_buy.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.relativelayout_send_product) {
            //发布产品
            Intent intent = new Intent(Main_Product_GuanLiActivity.this, Main_ChuangJain_ProductActivity.class);
            intent.putExtra("product_come_from", Contant.product_come_from_send);
            startActivity(intent);
        } else if (v.getId() == R.id.relativelayout_my_send_product) {
            //我发布的产品
            startActivity(new Intent(Main_Product_GuanLiActivity.this, Main_my_send_product_liebiaoActivity.class));
        } else if (v.getId() == R.id.relativelayout_add_fenlei) {
            //添加分类
            Intent intent = new Intent(Main_Product_GuanLiActivity.this, Main_ChuangJain_FenLeiActivity.class);
            intent.putExtra("fenlei_come_from", Contant.product_come_from_create_fenlei);
            startActivity(intent);
        } else if (v.getId() == R.id.relativelayout_product_fenlei) {
            //产品分类
            startActivity(new Intent(Main_Product_GuanLiActivity.this, Main_Indefine_FenLei_LieBiaoActivity.class));
        } else if (v.getId() == R.id.relativelayout_my_send_buy_product) {
            //我发布的求购
            startActivity(new Intent(Main_Product_GuanLiActivity.this, Main_my_qiugouActivity.class));
        } else if (v.getId() == R.id.relativelayout_my_collection_product) {
            //我收藏的产品
            Intent intent = new Intent(Main_Product_GuanLiActivity.this, Main_My_CollectionActivity.class);
            intent.putExtra("collection_type", "product");
            startActivity(intent);

        } else if (v.getId() == R.id.relativelayout_my_liuyan) {
            //我的产品留言
            Intent intent = new Intent(Main_Product_GuanLiActivity.this, Main_My_product_liuyanActivity.class);
            intent.putExtra("liuyan_comeFrom", Contant.come_from_my_product_liuyan);
            startActivity(intent);

        } else if (v.getId() == R.id.relativelayout_my_receive_liuyan) {
            //我收到的产品留言
            /**
             * 企业账号：我收到产品的留言
             */
            Intent intent = new Intent(Main_Product_GuanLiActivity.this, Main_My_product_liuyanActivity.class);
            intent.putExtra("liuyan_comeFrom", Contant.come_from_my_receiver_product_liuyan);
            startActivity(intent);
        } else if (v.getId() == R.id.product_relative_guanli_back) {
            Main_Product_GuanLiActivity.this.finish();
        } else if (v.getId() == R.id.relativelayout_send_product_buy) {
            startActivity(new Intent(Main_Product_GuanLiActivity.this, Main_Send_Want_Buy_ProductActivity.class));
        }

    }


}
